//
//  FreebaseQuerier.h
//  Freebase
//
//  Created by Alec Flett on 7/26/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Freebase.h"
#import "FreebaseDelegate.h"

@interface FreebaseQuerier : NSObject <FreebaseRequest> {
    NSMutableData *responseData;
    id delegate;
    FreebaseSession *_session;
    NSString *queryName;
    BOOL _isJson;
    BOOL _isNamedResponse;
    BOOL _isResultResponse;
    BOOL _wantsRawData;
    BOOL _cancelled; // has cancel been called?
    NSInteger _responseCode;
    SEL responseSelector;
    NSString *_transactionId;
    NSURLConnection *_connection;
}

@property(retain, readonly, nonatomic) id delegate;
@property(nonatomic, retain) NSString* queryName;
@property(nonatomic) BOOL isJson;
@property(nonatomic) BOOL isNamedResponse;
@property(nonatomic) BOOL isResultResponse;
@property(nonatomic) BOOL wantsRawData;

// just get the url for a service, formatting the url
- (FreebaseQuerier *)initWithDelegate:(id)del 
                         respSelector:(SEL)sel 
                            queryName:(NSString*)qName 
                              session:(FreebaseSession*)session;
- (void)requestUrl: (NSString*)relativeUrl;
- (void)requestUrl: (NSString*)relativeUrl cachePolicy:(NSURLCacheStoragePolicy)policy;
- (void)requestUrl:(NSString*)relativeUrl
          postForm:(NSDictionary*)postForm;
- (void)requestUrl: (NSString*)relativeUrl 
          postBody:(NSData*)postBody;

+ (NSString*)relativeUrlForService: (NSString*)url withArgs:(NSDictionary*)args;
+ (void)invokeCallback:(SEL)callbackSel
                target:(id)target
                result:(NSObject*)result
                  name:(NSString*)name
                cursor:(NSString*)cursor;

@end
